{% extends 'dashboard/base.html' %}

{% block body %}

    {#<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>#}
    <script type="text/javascript">

        $("#checkAll").change(function () {
            $("input:checkbox").prop('checked', $(this).prop("checked"));
        });
        $(document).ready(function () {
            $('.btn-danger').click(function () {
                if (confirm('Are you sure you want to delete this?')) {
                    var scan_id = ['a7af5b68-b661-45ad-90fd-ffa27526cdce'];
                    $.each($("input[name='del_vuln_id']:checked"), function () {
                        scan_id.push($(this).val());
                    });

                    var json_scanid = scan_id.join(", ");
                    $.ajax({
                        type: 'POST',
                        <!--contentType: 'application/json; charset=utf-8',-->
                        url: '{% url 'pentest:del_vuln' %}',
                        data: {
                            vuln_id: json_scanid,
                            scan_id: $('input[name=scan_id]').val(),
                            project_id: $('input[name=project_id]').val(),
                            csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val()
                        },
                        sucess: function () {
                        }
                    });
                    setTimeout(function(){location.reload();},1000);
                }
            });

        });

        $(document).on('click', '.confirm-delete', function () {
            return confirm('Are you sure you want to delete this?');
        })

    </script>


    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-body">
                    <div class="float-right">
                        {% if user.is_superuser == True or user.role.id == 2 %}
                            <div class="btn-group"><a
                                    href="{% url 'pentest:add_new_vuln' %}?scan_id={{ scan_id }}&vuln_id=&project_id={{ project_id }}"
                                    class="btn btn-primary btn-mini" data-toggle="tooltip" data-placement="top"
                                    title="Add New Vulnerability"><i
                                    class="fas fa-plus-circle"></i> Add </a>
                            </div>
                            <button type="button" class="btn btn-danger btn-mini" onclick="">Delete Selected</button>
                        {% endif %}

                    </div>
                    <br>
                    <div class="d-md-flex align-items-center">
                        <h1 class="card-title">Vulnerability List</h1>
                    </div>
                    <br>
                    <div class="row">
                        <div class="table-responsive">
                            <table id="data_table" class="table table-bordered data-table table-fixed">
                                <thead>
                                <tr>
                                    <th><label class="customcheckbox m-b-20">
                                        <input type="checkbox" id="mainCheckbox1">
                                        <span class="checkmark"></span>
                                    </label></th>
                                    <th>Vulnerability</th>
                                    <th>Risk</th>
<!--                                    <th>JIRA Ticket</th>-->
                                    <th>Status</th>
                                {% if user.is_superuser == True or user.role.id == 2 %}
                                    <th>Edit</th>
                                {% endif %}
                                    {% if user.is_superuser == True or user.role.id == 2 %}
                                        <th>Mark</th>
                                    {% endif %}
                                    {% if user.is_superuser == True or user.role.id == 2 %}
                                        <th>Delete</th>
                                    {% endif %}
                                </tr>
                                </thead>
                                <tbody>{% for data in all_vuln %}
                                    <tr data-target="#">
                                        <td>
                                            <form>
                                                <label class="customcheckbox">
                                                    <input type="checkbox" class="listCheckbox1"
                                                           value="{{ data.vuln_id }}"
                                                           name="del_vuln_id"
                                                           onClick="reload">
                                                    <span class="checkmark"></span>
                                                </label>
                                            </form>
                                        </td>
                                        <td>
                                            <a href="{% url 'pentest:vuln_details' %}?vuln_id={{ data.vuln_id }}">{{ data.vuln_name }}</a>
                                        </td>
                                        <td><span
                                                class="badge badge-pill badge-{{ data.severity_color }}">{{ data.severity }}</span>
                                        </td>
<!--                                        <td><a href="{{jira_url}}browse/{{data.jira_ticket}}" target="_blank">{{data.jira_ticket}}</a>-->
<!--                                        </td>-->
                                        {% if data.vuln_status == 'Closed' %}
                                            <td><span
                                                    class="badge badge-pill badge-success">{{ data.vuln_status }}</span>
                                            </td>{% endif %}
                                        {% if data.vuln_status == 'Open' %}
                                            <td><span class="badge badge-pill badge-info">{{ data.vuln_status }}</span>
                                            </td>{% endif %}
                                   {% if user.is_superuser == True or user.role.id == 2 %}
                                        <td>
                                            <div><a href="{% url 'pentest:edit_vuln' %}?vuln_id={{ data.vuln_id }}"
                                                    class="btn btn-primary"
                                                    data-original-title="Edit"><i class="fas fa-edit"></i></a>
                                            </div>
                                        </td>
                                    {% endif %}
                                   {% if user.is_superuser == True or user.role.id == 2 %}
                                        {% if data.vuln_status == 'Open' %}
                                            <td>
                                                <form method="POST" action="{% url 'pentest:manual_vuln_data' %}">
                                                    {% csrf_token %}
                                                    <input type="hidden" name="vuln_id" value="{{ data.vuln_id }}">

                                                    <input type="hidden" name="status" value="Closed">
                                                    <input type="hidden" name="project_id"
                                                           value="{{ project_id }}">
                                                    <input type="hidden" name="scan_id" value="{{ data.scan_id }}">
                                                    <button class="btn btn-info btn-mini">Close</button>
                                                </form>
                                            </td>
                                        {% endif %}
                                        {% if data.vuln_status == 'Closed' %}
                                            <td>
                                                <form method="POST" action="{% url 'pentest:manual_vuln_data' %}">
                                                    {% csrf_token %}
                                                    <input type="hidden" name="vuln_id" value="{{ data.vuln_id }}">

                                                    <input type="hidden" name="status" value="Open">
                                                    <input type="hidden" name="project_id"
                                                           value="{{ project_id }}">
                                                    <input type="hidden" name="scan_id" value="{{ data.scan_id }}">
                                                    <button class="btn btn-info btn-mini">Open</button>
                                                </form>
                                            </td>
                                        {% endif %}
                                    {% endif %}
                                       {% if user.is_superuser == True or user.role.id == 2 %}
                                            <td class="confirm-delete">
                                                <div>
                                                    <form action="{% url 'pentest:del_vuln' %}" method="POST"
                                                          class="form-horizontal">
                                                        {% csrf_token %}
                                                        <input type="hidden" name="vuln_id" value="{{ data.vuln_id }}">
                                                        <input type="hidden" name="scan_id" value="{{ data.scan_id }}">
                                                        <input type="hidden" name="project_id" value="{{ project_id }}">
                                                        <button class="btn btn-warning"><i class="fas fa-trash"></i>
                                                        </button>
                                                    </form>
                                                </div>
                                            </td>
                                        {% endif %}
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>

{% endblock %}
